MKCONF_DIR = ../mkconfig
LIBC_DIR = ../libc
UTILS_DIR = ../utils

include $(MKCONF_DIR)/compile.mk
include $(MKCONF_DIR)/config.mk
-include $(MKCONF_DIR)/sdk.mk

#CONF_FILES += $(TOPDIR)/../utility/configs/$(BOARD)/config.mk
CONF_FILES += $(TOPDIR)/../base/model/$(BOARD)/config/config.mk

ifneq ($(MAKECMDGOALS),clean)
AUTOCONF_MK = $(BUILD_DIR)\autoconfig.mk
sinclude $(AUTOCONF_MK)
endif

Target = build/sys_$(BOARD)
Middle = $(obj)/sys_$(BOARD)

CPPFLAGS += -I../utility/include -I../base/model/$(BOARD)/config -I../base/include
export CPPFLAGS

SOBJS-y :=
COBJS-y	:= $(BOARD)\main.o $(BOARD)\$(BOARD).o $(BOARD)\ota.o

SRCS := $(COBJS-y:.o=.c)
OBJS := $(addprefix $(obj)/, $(COBJS-y))

NEED_BUILD_INFO := yes

LINKSCRIPT := $(BOARD)/sh.ld

OBJS += ../base/build/$(BOARD)/libbase.o
OBJS += ../utility/build/$(BOARD)/libutility.o
LIBS :=	$(LIBC_DIR)/build/libc_$(ARCH).a
ifneq ($(MKSDK), )
RXLIB-y := ../base/fs/$(BOARD)/libfs.o
RXLIB-$(CONFIG_RFID_PN512) += ../base/drivers/rfid/libpn512.o
RXLIB-$(CONFIG_RFID_RC531) += ../base/drivers/rfid/librc531.o
RXLIB-$(CONFIG_ICC_GPIO) += ../base/drivers/icc_gpio/libicc_gpio.o
RXLIB-y += ../base/common/libcommon.o
RXLIB-y += ../utility/crypto/libcrypto.o
RXLIB-y += ../utility/code/libcode.o
RXLIB-y += ../utility/security/sec/libsec.o
else
RXLIB-y := ../base/fs/build/$(BOARD)/libfs.o
RXLIB-$(CONFIG_RFID_ISO14443) += ../base/drivers/rfid/build/$(BOARD)/librfid.o
RXLIB-$(CONFIG_ICC_GPIO) += ../base/drivers/icc_gpio/build/$(BOARD)/libicc_gpio.o
RXLIB-y += ../base/common/build/$(BOARD)/libcommon.o
RXLIB-y += ../utility/crypto/build/$(BOARD)/libcrypto.o
RXLIB-y += ../utility/code/build/$(BOARD)/libcode.o
RXLIB-y += ../utility/security/sec/build/$(BOARD)/libsec.o
endif

LIBS += $(RXLIB-y)
OS_TIME = $(shell  echo %date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%-%time:~3,2%-%time:~6,2%)



all: $(Target).bin $(Target).hex

all: signature
signature: $(Target).bin
	@echo Signature the output binary to build/rxsys.bin ...
	@$(UTILS_DIR)/rxDnw --file_path=$< --file_type=0 --result_name=build/rxsys.bin
	@echo Merging the rxBoot and rxSys to $(Target).rxsys.bin ...
	@$(CP) /y $(subst /,\,$(UTILS_DIR)/rxboot.sig.bin) $(subst /,\,$(Target).rxsys.bin)
	@$(DD) bs=4k if=build/rxsys.bin of=$(Target).rxsys.bin seek=4

dwn: $(Target).rxsys.bin
.PHONY:$(Target).rxsys.bin
$(Target).rxsys.bin: $(Target).bin
	@$(UTILS_DIR)/rxDnw --serial=com$(DWN_COMPORT) --file_type=0 --result_name=$(Target).rxsys.bin

dwn1: build/rxsys.bin
.PHONY:build/rxsys.bin
build/rxsys.bin: $(Target).bin
	@$(UTILS_DIR)/rxDnw --serial=com$(DWN_COMPORT) --file_type=0 --result_name=build/rxsys.bin

include $(MKCONF_DIR)/rules.mk
include $(MKCONF_DIR)/operation.mk
